import modelExtend from 'dva-model-extend'
// import { create, remove, update } from '../services/product'
import * as testResultService from '../services/testResult'
import { pageModel } from './common'
// import { config } from 'utils'

const { query,queryTop } = testResultService
;
export default modelExtend(pageModel, {
  namespace: 'testResult',

  state: {
    currentItem: {},
    modalVisible: false,
    // modalType: 'create',
    selectedRowKeys: [],
  },

  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen(location => {
        if (location.pathname === '/testResult') {
          dispatch({
            type: 'query',
            payload: location.query,
          })
        }
      })
    },
  },

  effects: {

    *query ( {payload={}}  , { call, put }) {
      const data = yield call(query, payload)
      const topData = yield call(queryTop, payload)
      if (data && topData) {
        let isString=typeof data.data
        let isString2=typeof topData.data
        console.log(isString,isString2)
        if(isString=='string' && isString2=='string'){
          let allList=[]
          allList.allData=JSON.parse(data.data)
          allList.topData=JSON.parse(topData.data)
          yield put({
            type: 'querySuccess',
            payload: {
              list: allList,
              pagination: {
                current: Number(payload.page) || 1,
                pageSize: 10,
                total: data.total,
                showSizeChanger:false,
                showQuickJumper:false
              },
            },
          })
        }

      }
    },




  },

  reducers: {

    showModal (state, { payload }) {
      return { ...state, ...payload, modalVisible: true }
    },

    hideModal (state) {
      return { ...state, modalVisible: false }
    },
  },
})
